package com.smart.common.utils;

import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;

public class SecurityUtils {

    public static UserDetails getUserDetails() {
        UserDetails userDetails;
        try {
            userDetails = (UserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        } catch (Exception e) {
            throw new RuntimeException("登录状态过期");
        }
        return userDetails;
    }

    /**
     * 是否为管理员
     * @param userId 用户ID
     * @return 结果
     **/
    public static boolean isAdmin(Long userId) {
        return userId != null && 1L == userId;
    }
    
}